import React from 'react'
import ReactDOM from 'react-dom'

class App extends React.Component {
  state = {
    count: 0,
  }
  render() {
    //   <button onClick={this.handleClick(1)}>+1</button> 这样写这就调this.handleClick事件
    return (
      <>
        <h1>hello react</h1>
        <button onClick={() => this.handleClick(-1)}>-1</button>
        <div>{this.state.count}</div>
        <button onClick={() => this.handleClick(1)}>+1</button>
      </>
    )
  }
  handleClick = (number) => {
    this.setState({
      count: this.state.count + number,
    })
  }
}

ReactDOM.render(<App />, document.getElementById('root'))
